package com.example.telesys.controller;

import com.example.telesys.pojo.*;
import com.example.telesys.service.CustomerorderService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/customerorder")
public class CustomerorderController {

    @Autowired
    private CustomerorderService customerorderService;

    @RequestMapping("/insertPhoneOrder")
    public int insertPhoneOrder(@RequestBody Customerorder customerorder) {
        return customerorderService.insertPhoneOrder(customerorder);
    }

    @RequestMapping("/insertBroadbandOrder")
    public int insertBroadbandOrder(@RequestBody Customerorder customerorder) {
        return customerorderService.insertBroadbandOrder(customerorder);
    }

    @RequestMapping("/insertTrafficOrder")
    public int insertTrafficOrder(@RequestBody Customerorder customerorder) {
        return customerorderService.insertTrafficOrder(customerorder);
    }

    @RequestMapping("/selectMyOrders")
    public PageInfo selectMyOrders(
            @RequestParam("username") String username,
            @RequestParam("currentPageNumber")Integer currentPageNumber,
            @RequestParam("currentPageSize")Integer currentPageSize) {
        PageHelper.startPage(currentPageNumber, currentPageSize);
        List<Customerorder> list = customerorderService.selectMyOrders(username);
        PageInfo pageInfo = new PageInfo(list, currentPageSize);
        return pageInfo;
    }

    @RequestMapping("/selectAllCustomerOrders")
    public PageInfo selectAllCustomerOrders(@RequestParam("pageNumber") Integer pageNumber, @RequestParam("pageSize") Integer pageSize) {
        PageHelper.startPage(pageNumber, pageSize);
        List<Customerorder> list = customerorderService.selectAllCustomerOrders();
        PageInfo pageInfo = new PageInfo(list, pageSize);
        return pageInfo;
    }


    @RequestMapping("/selectCustomerAndNumber")
    public PageInfo selectCustomerAndNumber(@RequestParam("pageNumber") Integer pageNumber, @RequestParam("pageSize") Integer pageSize) {
        PageHelper.startPage(pageNumber, pageSize);
        List<Customerorder> list = customerorderService.selectCustomerAndNumber();
        PageInfo pageInfo = new PageInfo(list, pageSize);
        return pageInfo;
    }


    @RequestMapping("/selectYearlyOrder")
    public List<Customerorder> selectYearlyOrder(@RequestParam("username") String username,
                                                 @RequestParam("year") String year) {
        return customerorderService.selectYearlyOrder(username, year);
    }

    @RequestMapping("/setOrderStatus")
    public Integer setOrderStatus(
            @RequestParam("role") String role,
            @RequestParam("orderid") String orderid,
            @RequestParam("code") Integer code) {
        return customerorderService.setOrderStatus(role, orderid, code);
    }

    @RequestMapping("/selectCustomerOrdersByOrderId")
    public PageInfo selectCustomerOrdersByOrderId(
            @RequestParam("orderid") String orderid, @RequestParam("pageNumber") Integer pageNumber, @RequestParam("pageSize") Integer pageSize) {
        PageHelper.startPage(pageNumber, pageSize);
        List<Customerorder> list = customerorderService.selectCustomerOrdersByOrderId(orderid);
        PageInfo pageInfo = new PageInfo(list, pageSize);
        return pageInfo;
    }


}
